package com.niit.bean;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;


public class CityTopOneBean implements WritableComparable<CityTopOneBean> {


    private String Province;//省份
    private String City;//城市
    private long StudentsNum;//学生人数

    public CityTopOneBean() {
    }

    public CityTopOneBean(String Province, String City, long StudentsNum) {
        this.Province = Province;
        this.City = City;
        this.StudentsNum = StudentsNum;
    }

    public void set (String Province, String City, long StudentsNum) {
        this.Province = Province;
        this.City = City;
        this.StudentsNum = StudentsNum;
    }

    public String getProvince() {
        return Province;
    }

    public void setProvince(String Province) {
        this.Province = Province;
    }

    public String getCity() {
        return City;
    }

    public void setCity(String City) {
        this.City = City;
    }

    public long getStudentsNum() {
        return StudentsNum;
    }

    public void setStudentsNum(long StudentsNum) {
        this.StudentsNum = StudentsNum;
    }

    @Override
    public String toString() {
        return "省份："+Province+",城市："+City+",学生人数："+StudentsNum;
    }

    //todo 排序规则 根据州state正序进行排序 如果州相同 则根据确诊数量cases倒序排序
    @Override
    public int compareTo(CityTopOneBean o) {
        int result ;

        int i = Province.compareTo(o.getProvince());

        if ( i > 0) {
            result =1;
        } else if (i <0 ) {
            result = -1;
        } else {
            // 确诊病例数倒序排序
            result = StudentsNum > o.getStudentsNum() ? -1 : (StudentsNum < o.getStudentsNum()? 1:0);
        }

        return result;
    }

    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeUTF(Province);
        dataOutput.writeUTF(City);
        dataOutput.writeLong(StudentsNum);
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        this.Province =dataInput.readUTF();
        this.City =dataInput.readUTF();
        this.StudentsNum =dataInput.readLong();
    }
}
